package com.criticalritrpg.fichas;

import com.criticalritrpg.R;

import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class TabFichaAtributo extends Activity {
	private EditText edForca,edCarisma,edInteligencia,edConstituicao,edSabedoria,edDestresa;
	private Button btSalvarCampos;
	private int flag;
	public static FichaAtributo fichaAtributo;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.aba_ficha_atributos);
		setupCampos();
		fichaAtributo = FichaAtributo.getInstance();
		
		flag = getIntent().getFlags();
		if(flag==-1){
			//btSalvarCampos.setVisibility(View.INVISIBLE);
		}
		
		btSalvarCampos.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(flag==0){
					constroiFicha();
					}
					if(flag>0 || flag ==-1){
						carregaEd();
											
					}
				
			}
		});
		
		
	}
	
	
	
	protected void carregaEd() {
		// TODO Auto-generated method stub
		edForca.setText(String.valueOf(fichaAtributo.getForca()));
		edCarisma.setText(String.valueOf(fichaAtributo.getCarisma()));
		edInteligencia.setText(String.valueOf(fichaAtributo.getInteligencia()));
		edSabedoria.setText(String.valueOf(fichaAtributo.getSabedoria()));
		edDestresa.setText(String.valueOf(fichaAtributo.getDestreza()));
		edConstituicao.setText(String.valueOf(fichaAtributo.getConstituicao()));
	}



	protected void constroiFicha() {
		// TODO Auto-generated method stub
		fichaAtributo.setForca(Integer.parseInt(edForca.getText().toString()));
		fichaAtributo.setCarisma(Integer.parseInt(edCarisma.getText().toString()));
		fichaAtributo.setInteligencia(Integer.parseInt(edInteligencia.getText().toString()));
		fichaAtributo.setDestreza(Integer.parseInt(edDestresa.getText().toString()));
		fichaAtributo.setSabedoria(Integer.parseInt(edSabedoria.getText().toString()));
		fichaAtributo.setConstituicao(Integer.parseInt(edConstituicao.getText().toString()));
		
	}



	private void setupCampos(){
		edForca = (EditText) findViewById(R.id.forca);
		edCarisma = (EditText) findViewById(R.id.carisma);
		edInteligencia = (EditText) findViewById(R.id.inteligencia);
		edConstituicao = (EditText) findViewById(R.id.constituicao);
		edSabedoria = (EditText) findViewById(R.id.sabedoria);
		edDestresa = (EditText) findViewById(R.id.destreza);
		
		btSalvarCampos = (Button) findViewById(R.id.btSalvarAtributos);
	}



	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}

}
